﻿$(function () {
    //加载下拉框 审批状态
    $("#status").ligerComboBox({
        width: 80,
        data: [{ "ID": -1, "Name": "全部" }, { "ID": 0, "Name": "未审批" }, { "ID": 1, "Name": "审批通过" }, { "ID": 2, "Name": "审批拒绝" }],
        isMultiSelect: false,
        valueField: "ID",
        textField: "Name",
        value: '0',
        valueFieldID: 'hdnstatus',
    });
    $('#btnSearch').click(function () {
        search();
    });
    $('#btnSearch').click();
    $("#btnRollback").click(function () {
        var rows = grid.getCheckedRows();
        var str = "";
        $(rows).each(function () {
            str += this.ID + ",";
        });
        if (str == "")
            return;
        str = str.substring(0, str.length - 1);
        $.ligerDialog.open({
            height: 300,
            width: 420,
            title: '审批拒绝',
            url: '/TraumaCenter/GreenChannel/Approval?pass=2&id=' + str,
            showMax: false,
            showToggle: false,
            showMin: false,
            isResize: false,
            slide: false,
            data: {},
            buttons: [{
                text: '回调函数', onclick: function (i, d) {
                    $("#btnSearch").click();
                }
            }],
            cls: "closeCls"
        }).max();
        $(".l-dialog-buttons").hide();
    });
    $("#btnPass").click(function () {
        var rows = grid.getCheckedRows();
        var str = "";
        $(rows).each(function () {
            str += this.ID + ",";
        });
        if (str == "") return;
        str = str.substring(0, str.length - 1);
        $.ligerDialog.open({
            height: 300,
            width: 420,
            title: '审批通过',
            url: '/TraumaCenter/GreenChannel/Approval?pass=1&id=' + str,
            showMax: false,
            showToggle: false,
            showMin: false,
            isResize: false,
            slide: false,
            data: {},
            buttons: [{
                text: '回调函数', onclick: function (i, d) {
                    $("#btnSearch").click();
                }
            }],
            cls: "closeCls"
        }).max();
        $(".l-dialog-buttons").hide();
    });
    $(document).on("click", ".closeCls", function () {
        $("#btnSearch").click();
    });
});
function opennewtab(patientId, patientName) {
    window.parent.top.tab.addTabItem({ tabid: patientId, text: "创伤病历", url: "/TraumaCenter/MedicalRecords/Index?patientId=" + patientId });
}
//查询功能
function search(pageNumber) {
    var queryData = {
        name: $("#txtName").val(),
        status: $("#hdnstatus").val()
    }
    initTable(queryData, 1);
}
//显示表数据
var grid;
function initTable(queryData, pageNumber) {
    grid = $("#maingrid").ligerGrid({
        checkbox: true,
        height: '100%',
        url: '/TraumaCenter/GreenChannel/Search?ram=' + new Date().getMilliseconds(),
        parms: queryData,
        page: pageNumber,
        pageSize: 30,
        rownumbers: false,
        heightDiff: -5,
        columns: [
{ display: '就诊ID', name: 'PATIENT_ID', minWidth: 50 },
{
    display: '姓名', name: 'PATIENT_NAME', minWidth: 100, render: function (row) {
        return "<a style=\"cursor:pointer;\" onclick=\"opennewtab('" + row.PATIENT_ID + "','" + row.PATIENT_NAME + "')\" >" + row.PATIENT_NAME + "</a>";
    }
},
{
    display: '性别', name: 'PATIENT_SEX', minWidth: 50,
    render: function (rowData) {
        if (IsEmpty(rowData.PATIENT_SEX)) return "未知";
        if (rowData.PATIENT_SEX == "1") return "男";
        if (rowData.PATIENT_SEX == "0") return "女";
        return rowData.PATIENT_SEX;;
    }
},
{ display: '年龄', name: 'PATIENT_AGE', minWidth: 50 },
{
    display: '审批状态', name: 'ApprovalStatus', minWidth: 50,
    render: function (rowData) {
        if (IsEmpty(rowData.ApprovalStatus) || rowData.ApprovalStatus == "0") return "未审批";
        if (rowData.ApprovalStatus == "1") return "<span style=\"color:green\" >审批通过</span>";
        if (rowData.ApprovalStatus == "2") return "<span style=\"color:red\" >审批拒绝</span>";
        return "未审批";
    }
},
{ display: '审批备注', name: 'ApprovalRemark', minWidth: 50 }
        ],
        isScroll: true,
        onSuccess: function (data, grid) {
            $("#spanPatientNum").text(data.Total);
            $("#spanInHospitalNum").text(data.InHospitalNum);
            $("#spanPreHospitalNum").text(data.PreHospitalNum);
        }
    });
}